package com.xmotor.testjavaxvalidation.validator;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Description 验证器
 * @Author XUZS
 * @Date 20-2-24 15:49
 * @Version 1.0
 **/
@Slf4j
public class PlateTypeValidator implements ConstraintValidator<PlateType, String> {

    private final String type1 = "02";    //小汽车
    private final String type2 = "52";    //新能源小汽车

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {

        if (StringUtils.isBlank(value)){
            return true;
        }

        if(type1.equals(value) || type2.equals(value)){
            return true;
        }
        else {
            return false;
        }
    }

    @Override
    public void initialize(PlateType constraintAnnotation) {

    }
}
